﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Common.Helper
{
    public class PorpertieHelper
    {
        public static void CopyProperties(Object origin, Object target)
        {
            Type originType = origin.GetType();
            PropertyInfo[] originProps = originType.GetProperties();
            foreach (var originProp in originProps)
            {
                PropertyInfo destProp = target.GetType().GetProperty(originProp.Name);
                if (destProp != null)
                {
                    try
                    {
                        destProp.SetValue(target, originProp.GetValue(origin));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }
    }
}
